<?php

namespace builder\test\controllers;

use builder\base\BaseController;
use builder\card\CardBuilder;
use builder\helper\H5;
use builder\widget\ajax\BlockModal;
use builder\widget\WidgetFacade;

/**
 * 测试模块默认路由
 */
class IndexController extends BaseController
{
    public $actionVerbs = [
        'index' => ['GET', 'POST'],
    ];
    public $publicActions = ['index'];
    private $_exampleProvider = [
        //Web Component (block)
        ['route' => 'ymtest/comp/block?_partial=1', 'name' => 'Web Component (block) Example', 'modalTitle' => 'Web Component (block) Example', 'width' => '616px', 'height' => '170px'],
        //Card Builder Example
        ['route' => 'ymtest/card/index?_partial=1', 'name' => 'Card Builder Example', 'modalTitle' => 'Card Builder Example', 'width' => null, 'height' => null],
        //Form Builder Example
        ['route' => 'ymtest/form/index?_partial=1', 'name' => 'Form Builder Example1', 'modalTitle' => 'Form Builder Example1', 'width' => '1250px', 'height' => '700px'],
        ['route' => 'ymtest/form/dynamic?_partial=1', 'name' => 'Form Builder Example2', 'modalTitle' => 'Form Builder Example2', 'width' => '1250px', 'height' => '700px'],
        ['route' => 'ymtest/form/dynamic2?_partial=1', 'name' => 'Form Builder Example3', 'modalTitle' => 'Form Builder Example3', 'width' => '1150px', 'height' => '850px'],
        //Form Step Builder Example
        ['route' => 'ymtest/form-step/index?_partial=1', 'name' => 'Form Step Builder Example', 'modalTitle' => 'Form Step Builder Example', 'width' => '800px', 'height' => '600px'],
        //List Builder Example
        ['route' => 'ymtest/lists/index?_partial=1', 'name' => 'List Builder Example', 'modalTitle' => 'List Builder Example', 'width' => '960px', 'height' => '700px'],
        //Menu Builder Example
        ['route' => 'ymtest/menu/m-index?_partial=1', 'name' => 'Menu Builder Example', 'modalTitle' => 'Menu Builder Example', 'width' => '1170px', 'height' => '550px'],
        //Tab Builder Example
        ['route' => 'ymtest/tab/index?_partial=1&theme=card', 'name' => 'Tab Builder Example (card)', 'modalTitle' => 'Tab Builder Example card', 'width' => '880px', 'height' => '700px'],
        ['route' => 'ymtest/tab/index?_partial=1&theme=column', 'name' => 'Tab Builder Example (column)', 'modalTitle' => 'Tab Builder Example column', 'width' => '780px', 'height' => '660px'],
        ['route' => 'ymtest/tab/index?_partial=1&theme=brief', 'name' => 'Tab Builder Example (brief)', 'modalTitle' => 'Tab Builder Example brief', 'width' => '880px', 'height' => '700px'],
        //Table Builder Example
        ['route' => 'ymtest/table/index?_partial=1', 'name' => 'Table Builder Example', 'modalTitle' => 'Table Builder Example', 'width' => '1200px', 'height' => '850px'],
        //Tree Builder Example
        ['route' => 'ymtest/tree/index?_partial=1', 'name' => 'Tree Builder Example', 'modalTitle' => 'Tree Builder Example', 'width' => '520px', 'height' => '685px'],
        //Tree-Table Builder Example
        ['route' => 'ymtest/tree-table/index?_partial=1', 'name' => 'Tree-Table Builder Example', 'modalTitle' => 'Tree-Table Builder Example', 'width' => '1230px', 'height' => '860px'],
        //Layui Timeline Example
        ['route' => 'ymtest/widget/index?_partial=1', 'name' => 'Layui Timeline Example', 'modalTitle' => 'Layui Timeline Example', 'width' => '550px', 'height' => '730px'],
        //Layui Progress Example
        ['route' => 'ymtest/widget/progress?_partial=1', 'name' => 'Layui Progress Example', 'modalTitle' => 'Layui Progress Example', 'width' => '550px', 'height' => '650px'],
        //Layui Carousel Example
        ['route' => 'ymtest/widget/carousel?_partial=1', 'name' => 'Layui Carousel Example', 'modalTitle' => 'Layui Carousel Example', 'width' => '960px', 'height' => '700px'],
        //Widget Other Example
        ['route' => 'ymtest/widget/other?_partial=1', 'name' => 'Widget Other Example', 'modalTitle' => 'Widget Other Example', 'width' => '1200px', 'height' => '850px'],
    ];

    //获取示例
    protected function example($url, $label, $modalTitle, $width, $height)
    {
        return WidgetFacade::echo2Return(function () use ($url, $label, $modalTitle, $width, $height) {
            BlockModal::begin([
                'url' => $url,
                'title' => $modalTitle,
                'width' => isset($width) ? $width : '82%',
                'height' => isset($height) ? $height : '72%',
            ]);
            echo H5::text($label, [
                'class' => ['h-50px', 'd-flex', 'align-items-center', 'justify-content-center', 'cp'],
            ], 'div');
            BlockModal::end();
        });
    }

    //快捷项
    public function actionIndex()
    {
        $cardItems = [];
        foreach ($this->_exampleProvider as $item) {
            $cardItems[] = $this->cardItem
                ->panel()
                ->body(function () use ($item) {
                    return $this->example($item['route'], $item['name'], $item['modalTitle'], $item['width'], $item['height']);
                })
                ->uiClass('w-250 text-center m-3');
        }

        $cardBuilder = CardBuilder::instance(['id' => 'Ymtest_Card_Index']);
        $cardBuilder->setTitle('Card')
            ->setCardItem([
                $this->cardItem->card()->header('Yii Manager 组件示例')->body(function (CardBuilder $cardBuilder) use ($cardItems) {
                    return $cardBuilder->setId('Ymtest_Card_Index_Item')->setCardItem($cardItems);
                }),
            ]);

        return $cardBuilder->render();
    }
}